#include "DE15.h"
#include "stm32f1xx_hal.h"
#include "dataprocess.h"
/*UART Receive Buffer Size*/
struct s_filter lpFilter;
void lpFilterInit(int channle)
{
	lpFilter.m_chmove=12;
	lpFilter.m_nCoefNumb=2;
	lpFilter.m_pa[0]=4096;
	lpFilter.m_pa[1]=-3440;
	lpFilter.m_pb[0]=328;
	lpFilter.m_pb[1]=328;
	for(int8_t i=0;i<channle;i++)
	{
		lpFilter.m_px[channle][0]=0;
		lpFilter.m_px[channle][1]=0;
		lpFilter.m_py[channle][0]=0;
		lpFilter.m_py[channle][1]=0;
	}

}
int dataLpFilter(int xt,int index)
{

        int i=0;
        I64 tmp=0;
        I64 yt=0;
        for(i=2-1;i>0;i--)
        {
                lpFilter.m_px[index][i]=lpFilter.m_px[index][i-1];
                lpFilter.m_py[index][i]=lpFilter.m_py[index][i-1];
        }
        lpFilter.m_px[index][0]=(I64)xt;

        for(i=0,tmp=0;i<lpFilter.m_nCoefNumb;i++)
        {
                tmp+=lpFilter.m_px[index][i]*lpFilter.m_pb[i];
                if(i)
                tmp-=lpFilter.m_py[index][i]*lpFilter.m_pa[i];
        }

        yt=tmp>>lpFilter.m_chmove;
        lpFilter.m_py[index][0]=yt;

        return yt;
////    /*for debug*/
////    return xt;
}


